﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Compte
{
    public partial class frmCreateCompte : Form
    {
        frmCompte AAppeller;
        public frmCreateCompte()
        {
            InitializeComponent();
        }
        public frmCreateCompte(frmCompte f)
        {
            InitializeComponent();
            AAppeller = f;
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            Regex bignumber = new Regex(@"^\d+([\.|,]\d{1,2})?$");
            Regex smallnumber = new Regex(@"^0[\.|,]\d{1,2}$");
            if (txtNom.Text != "" && txtSolde.Text != "")
            {
                if(bignumber.IsMatch(txtSolde.Text) || smallnumber.IsMatch(txtSolde.Text)){
                    ComposanteSQL.Insert<Utilisateur>(new Utilisateur(txtNom.Text, Decimal.Parse(txtSolde.Text)));
                    ComposanteSQL.Insert<Compte>(new Compte("Principal", Decimal.Parse(txtSolde.Text), txtNom.Text));
                    AAppeller.Visible = true;
                    AAppeller.setUser();
                    this.Dispose();
                    this.Close();
                }
            }
        }
    }
}
